package com.example.demo.demos.web.service;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

@Service
public class TtsService {

    @Value("${ttl.text}")
    private String text;

    @Value("${ttl.speed}")
    private Integer speed;

    @Value("${ttl.volume}")
    private Integer volume;

    @Value("${ttl.pitch}")
    private Integer pitch;

    private final RestTemplate restTemplate;

    public TtsService(RestTemplate restTemplate){
        this.restTemplate = restTemplate;
    }



    public String buildAudioPlayUrl(){

        try {
            String encodedText = URLEncoder.encode(text, String.valueOf(StandardCharsets.UTF_8));
            return String.format("http://192.168.131.24:8774/forward?text=%s&speed=%d&volume=%d&pitch=%d",
                    encodedText, speed, volume, pitch);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }

    }
}
